/*
 * Copyright (C) Michael Opitz
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA
 */
#ifndef WEB_ACCEPTOR_H
#define WEB_ACCEPTOR_H

#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>

#include "../handler/event_handler.h"
#include "../handler/multicaster.h"
#include "../network/configurator.h"
#include "../music/music_system.h"

#include "web_handler.h"

/** 
 * \brief This namespace includes all user-specific handlers for the iRoom.
 * \author Michael Opitz
 */
namespace user_handler {
	/** 
	 * \brief This class creates new web_handler if a new connection with a
	 * web-client is established.
	 */
	class web_acceptor : public handler::event_handler {
	public:
		/** 
		 * \brief web_acceptor creates a new web-acceptor
		 * 
		 * \param sock is the socket to the web-listener
		 * \param control is the socket to the microcontroller
		 * \param mgr is a pointer to the connection_manager
		 * \param mul is a pointer to the multicaster
		 * \param music is a pointer to the music-system
		 */
		web_acceptor(boost::shared_ptr<network::i_socket> sock,
			     boost::shared_ptr<network::i_socket> control,
			     boost::shared_ptr<network::connection_manager> mgr,
			     boost::weak_ptr<handler::multicaster> mul,
			     boost::shared_ptr<music::music_system> music)
		:_sock(sock), _controller(control), _mgr(mgr), _multi(mul), 
			_music(music) {}
		
		virtual ~web_acceptor() {}

		/** 
		 * \brief handle_event handles events from the web-listener
		 * 
		 * \param n is the received message.
		 */
		virtual void handle_event(
			boost::shared_ptr<network::message> n);
	private:
		boost::shared_ptr<network::i_socket> _sock;
		boost::shared_ptr<network::i_socket> _controller;
		boost::shared_ptr<network::connection_manager> _mgr;

		boost::weak_ptr<handler::multicaster> _multi;
		boost::shared_ptr<music::music_system> _music;
	};
}

#endif
